package com.alks.function.controller;

import com.alks.common.aop.ApiRestController;
import com.alks.entity.data.entity.SdDepartment;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.service.SdDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@ApiRestController("/dept")
@Api(tags = "部门资料")
@Slf4j
public class SdDepartmentController {

    @Autowired
    private SdDepartmentService sdDepartmentService;

    @ApiOperation(value = "查询所有")
    @GetMapping("/GetAllData")
    public ResponseInfo GetAllData(){
        return sdDepartmentService.FindAll();
    }

    @ApiOperation(value = "查询所有")
    @GetMapping("/last")
    public ResponseInfo lastDepartment(String searchKey){
        return sdDepartmentService.selectLastCombo(searchKey);
    }

    @ApiOperation(value = "添加部门")
    @PostMapping("/AddDepartmentInfo")
    public ResponseInfo AddDepartmentInfo(@RequestBody SdDepartment sdDepartment){

        return sdDepartmentService.SaveDepartmentInfo(sdDepartment);
    }

    @ApiOperation("查询单个")
    @GetMapping("/getDepartmentInfo")
    public ResponseInfo getDepartmentInfo(@RequestParam(value = "deptNo") String deptNo){
        return sdDepartmentService.FinDepartmentInfo(deptNo);
    }

    @ApiOperation("修改部门")
    @PutMapping("/updateDepartmentInfo")
    public ResponseInfo updateDepartmentInfo(@RequestBody SdDepartment sdDepartment){
        return sdDepartmentService.updateWithDepartment(sdDepartment);
    }

    @ApiOperation(value = "删除部门")
    @PostMapping("/delDepartmentInfo")
    public ResponseInfo delDepartmentInfo(@RequestBody SdDepartment sdDepartment){
        return sdDepartmentService.delDepartmentInfo(sdDepartment);
    }
}
